﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SpringStudio.Common;
using SpringStudio.DAL;

namespace Sdepci.InfoCode.BLL.Authority
{
    /// <summary>
    /// 功能菜单类
    /// </summary>
    public class Function
    {
        #region 属性定义

        private string _funcGuid;
        /// <summary>
        /// 功能菜单Guid
        /// </summary>
        public string FuncGuid
        {
            get { return this._funcGuid; }
        }

        private string _parentFuncGuid;
        /// <summary>
        /// 父节点Guid
        /// </summary>
        public string ParentFuncGuid
        {
            get { return this._parentFuncGuid; }
        }

        private string _funcDesc;
        /// <summary>
        /// 功能菜单说明
        /// </summary>
        public string FuncDesc
        {
            get { return this._funcDesc; }
        }

        private string _funcUrl;
        /// <summary>
        /// Url地址
        /// </summary>
        public string FuncUrl
        {
            get { return this._funcUrl; }
        }

        private string _funcIcon;
        /// <summary>
        /// 菜单图标
        /// </summary>
        public string FuncIcon
        {
            get { return this._funcIcon; }
        }

        private int _seq;
        /// <summary>
        /// 显示次序
        /// </summary>
        public int Seq
        {
            get { return this._seq; }
        }

        #endregion

        #region 构造方法

        public Function(string funcGuid)
        {
            this._funcGuid = funcGuid;

            try
            {
                string sql = "Select ParentFuncGuid,FuncDesc,FuncUrl,FuncIcon,Seq From InfoCodeFunc Where FuncGuid=@FuncGuid";
                DataSet ds = SqlHelper.ExecuteDataSet(ConnectionString.Default, CommandType.Text, sql,
                    SqlHelper.NewSqlParameter("@FuncGuid", this._funcGuid));
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    DataRow row = ds.Tables[0].Rows[0];
                    this._parentFuncGuid = row["ParentFuncGuid"].ToString();
                    this._funcDesc = row["FuncDesc"].ToString();
                    this._funcUrl = row["FuncUrl"].ToString();
                    this._funcIcon = row["FuncIcon"].ToString();
                    this._seq = int.Parse(row["Seq"].ToString());
                }
                else
                {
                    throw new Exception("没有找到该值对应的详细记录！（参数：FuncGuid='" + this._funcGuid + "'）");
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }

        public Function(string funcGuid, string parentFuncGuid, string funcDesc, string funcUrl, string funcIcon, int seq)
        {
            this._funcGuid = funcGuid;
            this._parentFuncGuid = parentFuncGuid;
            this._funcDesc = funcDesc;
            this._funcUrl = funcUrl;
            this._funcIcon = funcIcon;
            this._seq = seq;
        }

        #endregion
    }
}
